package kt.com.bilin.coin.viewmodel

import kt.com.bilin.coin.api.API_SERVICE
import kt.com.bilin.coin.api.ApiObserver
import kt.com.bilin.coin.api.toData
import kt.com.bilin.coin.bean.AppVersionBean
import kt.com.bilin.coin.bean.BiLinAmountBean
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File


class UserViewModel : BaseViewModel() {
    fun appVersion(apiObserver: ApiObserver<AppVersionBean?>) {
        launchUI({ API_SERVICE.appVersion("1.0.8").toData() }, apiObserver = apiObserver)
    }

    fun faceVerify(idCardNo: String, name: String, file: File, apiObserver: ApiObserver<String?>) {
//        MultipartBody.Builder().apply {
//            addFormDataPart()
//        }
        launchUI({ API_SERVICE.faceVerify(idCardNo, name, MultipartBody.Part.createFormData("file", file.name, file.asRequestBody("multipart/form-data".toMediaType()))).toData() }, apiObserver = apiObserver)
    }

    fun kycAll(idCardNo: String, name: String, type: String, file: File, apiObserver: ApiObserver<String?>) {
        launchUI({
            API_SERVICE.kycAll(idCardNo, name, type, API_SERVICE.oldUpload(MultipartBody.Builder().apply { addFormDataPart("file", file.name, file.asRequestBody("multipart/form-data".toMediaType())) }.build()).toData()).toData()
        }, apiObserver = apiObserver)
    }

    fun getBlq(apiObserver: ApiObserver<BiLinAmountBean?>) {
        launchUI({ API_SERVICE.getBlq().toData() }, apiObserver = apiObserver)
    }

    fun kycCheckBefore(idCardNo: String, type: String, apiObserver: ApiObserver<String?>) {
        launchUI({ API_SERVICE.kycCheckBefore(idCardNo, type).toData() }, apiObserver = apiObserver)
    }
}